{
 "cells": [
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-08T13:29:49.760312Z",
     "start_time": "2025-05-08T13:29:49.755847Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import torch\n",
    "aa = torch.rand(2, 3, 2)\n",
    "print(aa)\n",
    "print(aa[:, -1, :])\n",
    "print(aa[:, [-1], :])"
   ],
   "id": "8c2e28161a262845",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[0.8051, 0.6614],\n",
      "         [0.4666, 0.0481],\n",
      "         [0.4704, 0.7475]],\n",
      "\n",
      "        [[0.6037, 0.9877],\n",
      "         [0.9969, 0.4413],\n",
      "         [0.2592, 0.0874]]])\n",
      "tensor([[0.4704, 0.7475],\n",
      "        [0.2592, 0.0874]])\n",
      "tensor([[[0.4704, 0.7475]],\n",
      "\n",
      "        [[0.2592, 0.0874]]])\n"
     ]
    }
   ],
   "execution_count": 21
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-08T13:29:49.845014Z",
     "start_time": "2025-05-08T13:29:49.840849Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import torch\n",
    "aa = torch.rand(2, 3)\n",
    "l = torch.nn.Linear(3, 2, bias=False)\n",
    "print(l(aa))\n",
    "print(aa @ l.weight.T)\n",
    "print(l.weight @ aa.T)"
   ],
   "id": "f5ac3ccd8f1dbb73",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[ 0.5444,  0.0394],\n",
      "        [ 1.0358, -0.2069]], grad_fn=<MmBackward0>)\n",
      "tensor([[ 0.5444,  0.0394],\n",
      "        [ 1.0358, -0.2069]], grad_fn=<MmBackward0>)\n",
      "tensor([[ 0.5444,  1.0358],\n",
      "        [ 0.0394, -0.2069]], grad_fn=<MmBackward0>)\n"
     ]
    }
   ],
   "execution_count": 22
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-08T13:29:49.941407Z",
     "start_time": "2025-05-08T13:29:49.936901Z"
    }
   },
   "cell_type": "code",
   "source": [
    "cc = torch.arange(20).reshape(-1, 5)\n",
    "print(cc)\n",
    "dd = cc <= 11\n",
    "print(dd)\n",
    "print(cc[dd])"
   ],
   "id": "26e86e9bde257d1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[ 0,  1,  2,  3,  4],\n",
      "        [ 5,  6,  7,  8,  9],\n",
      "        [10, 11, 12, 13, 14],\n",
      "        [15, 16, 17, 18, 19]])\n",
      "tensor([[ True,  True,  True,  True,  True],\n",
      "        [ True,  True,  True,  True,  True],\n",
      "        [ True,  True, False, False, False],\n",
      "        [False, False, False, False, False]])\n",
      "tensor([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])\n"
     ]
    }
   ],
   "execution_count": 23
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-08T13:29:50.012888Z",
     "start_time": "2025-05-08T13:29:50.008842Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import numpy as np\n",
    "source_data = np.random.rand(100, 5)  # 100个样本，特征维度为5\n",
    "source_labels = np.random.randint(0, 10, size=100)  # 二分类标签\n",
    "print(len(source_data), len(source_data[0]))\n",
    "print(source_labels)"
   ],
   "id": "c6eb4f886297263",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100 5\n",
      "[7 3 9 5 1 2 9 2 7 5 6 4 5 2 7 0 3 0 4 1 7 4 5 1 0 4 5 8 9 8 8 2 6 9 6 0 7\n",
      " 3 5 1 6 9 4 1 6 3 1 7 0 6 5 9 9 6 2 9 1 1 7 4 0 5 8 4 6 9 4 9 6 6 3 7 1 4\n",
      " 7 4 1 7 4 4 6 4 9 2 6 0 4 7 9 7 8 7 1 2 1 2 8 4 5 7]\n"
     ]
    }
   ],
   "execution_count": 24
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-20T15:48:50.306012Z",
     "start_time": "2025-05-20T15:48:50.302503Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import torch\n",
    "cc = torch.arange(20).reshape(-1, 5)\n"
   ],
   "id": "fa108b5112afb3ec",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Tensor"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-20T15:54:01.357839Z",
     "start_time": "2025-05-20T15:54:01.354899Z"
    }
   },
   "cell_type": "code",
   "source": [
    "aa = [1, 2, 3]\n",
    "bb = [4, 5, 6]\n",
    "dd = aa + bb\n",
    "dd"
   ],
   "id": "f23f037faf49cde7",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 18
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "e8c2ff2c226553d0"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
